package com.blockmeta.bbs.minemodule.activity;

import android.content.Context;

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;

import com.blockmeta.bbs.baselibrary.provider.IApplicationProvider;
import com.blockmeta.bbs.baselibrary.utils.ViewUtils;
import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.base.BaseActivity;
import com.blockmeta.bbs.businesslibrary.dialog.CheckDialog;
import com.blockmeta.bbs.businesslibrary.launch.contactusYMAL;
import com.blockmeta.bbs.businesslibrary.pojo.ContactUSPOJO;
import com.blockmeta.bbs.minemodule.R;
import com.blockmeta.bbs.minemodule.R2;
import com.blockmeta.bbs.minemodule.adapter.ContactUsAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;

import butterknife.BindView;


/**
 * Created by author on 2018/4/9.
 */

public class ContactUsActivity extends BaseActivity {
    @BindView(R2.id.list_recy)
    RecyclerView mListRecy;
    @BindView(R2.id.list_swipe)
    SwipeRefreshLayout mListSwipe;
    private Context mContext;
    ContactUSPOJO sContactUSPOJO = contactusYMAL.getContactUSPOJO();
    @Override
    protected boolean showTitle() {
        return true;
    }

    @Override
    public View setView() {
        setTitleText("联系我们");
        mContext = ContactUsActivity.this;
        return LayoutInflater.from(mContext).inflate(R.layout.fragment_list, null);
    }


    @Override
    protected void initialize() {
        super.initialize();
        mListSwipe.setEnabled(false);
        mListRecy.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));

        if(sContactUSPOJO.getConnectus().size() == 2) {
            IApplicationProvider provider = RouterHelper.getProvider(RouterPath.APPLICATION_PROVIDER);
            ContactUSPOJO.ConnectusBean bean = new ContactUSPOJO.ConnectusBean();
            bean.setKey("版本");
            bean.setValue(provider.getProjectBuildInfo().version_name);
            sContactUSPOJO.getConnectus().add(bean);
            bean = new ContactUSPOJO.ConnectusBean();
            bean.setKey("版本号");
            bean.setValue(provider.getProjectBuildInfo().version_code + "");
            sContactUSPOJO.getConnectus().add(bean);
        }
        ContactUsAdapter adapter = new ContactUsAdapter(R.layout.item_zxing_ecode, sContactUSPOJO.getConnectus());
        mListRecy.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (TextUtils.isEmpty(sContactUSPOJO.getConnectus().get(position).getLink())) {
                    String describe = sContactUSPOJO.getConnectus().get(position).getDescribe();
                    CheckDialog.showContactNotifation((ContactUsActivity) mContext, describe);
                    ViewUtils.copyText(mContext, sContactUSPOJO.getConnectus().get(position).getValue(),false);
                } else {
                    RouterHelper.startActivity(mContext, RouterPath.WEB_ACTIVITY,sContactUSPOJO.getConnectus().get(position).getLink(),"资讯投稿");
                }
            }
        });
    }
}
